<?php
declare (strict_types=1);

namespace app\admin\controller\admin;

use app\admin\annotation\common\Auth;
use app\admin\controller\Admin;
use app\admin\model\admin\Config as ConfigModel;
use app\admin\service\common\SortableService;
use app\admin\validate\admin\Config as ConfigValidate;
use app\common\Constants;
use think\App;
use think\db\exception\DbException;
use think\facade\Log;

class Config extends BaseConfig
{

    #[Auth('admin:config:add')]
    public function add(): \think\response\Json
    {
        $post = $this->request->post();
        try {
            // 参数验证
            validate(ConfigValidate::class)->scene('add')->check($post);
            // 新增
            $this->configModel->create($post);
            // 更新系统配置缓存
            \think\facade\Cache::delete('admin_config_data');
            // 返回
            return $this->success();
        } catch (\think\Exception\ValidateException $ve) {
            return $this->error(['msg' => $ve->getMessage()]);
        } catch (\Exception $e) {
            throw $e;
        }
    }

}
